<?php
/**
 * Created by JetBrains PhpStorm.
 * User: 蒋文书
 * Date: 14-12-27
 * Time: 下午8:50
 * To change this template use File | Settings | File Templates.
 */

namespace Admin\Model;
use Think\Model;

class ChannelModel extends Model {
   
    /**
     * 新增模型
     * @return 
     * @author 蒋文书 <jiangwenshu1990@126.com>
     */
    public function add(){     
        //创建数据对象
        $data = M('model')->create();
        if(!$data){
            $this->error='创建数据对象错误!';
        }
        return M('Channel')->add($data);
    }

     /**
     * 获取模型字段
     * @return 
     * @author 蒋文书 <jiangwenshu1990@126.com>
     */
    public function get_model_id($model_id,$isChannel){
        //表前缀
        $dbPrefix = C("DB_PREFIX");
        /* 非法ID */
        if(empty($model_id) || !is_numeric($model_id)){
            return '';
        }
        $modelCount=M('model')->where(array('model_id'=>$model_id))->count();
        if(!$modelCount){
           $this->error='请选择要操作的数据ID!'; 
        }
        return M('model_field')->where(array('status'=>1,'model_id'=>$model_id,'is_channel'=>$isChannel))->order('sort asc')->select();

    }


    /**
     * 递归调用栏目
     * @return $arr;
     * @author 蒋文书 <jiangwenshu1990@126.com>
     */
    public function getChannel($channelList,$pid='0',$html='——',$level='0'){
      $arr = array();
      foreach($channelList as $val){
        if($val['pid']==$asmenu){
          $val['html'] = str_repeat($html,$level);
          $arr[] = $val;
          $arr = array_merge($arr,self::getCategory($catlist,$val['pid'],$html,$level+1));
          //dump($arr);
          //exit();
        }  
      }
      return $arr;
    }
 

   



}
 